﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using YunShop_WebAPI.Model;

namespace YunShop_WebAPI.BLL
{   
    public class MemberShopService
    {
        /// <summary>
        /// 电子会员卡
        /// </summary>
        public static string YunShopUrl = System.Configuration.ConfigurationManager.AppSettings["YunShopUrl"].ToString();

        /// <summary>
        /// 通过appid获取密钥
        /// </summary>
        /// <param name="appid"></param>
        /// <returns></returns>
        public static List<MemberDataResponse> GetMemberData(string sSystemAppID)
        {
            int mCorpID = SystemInfo.GetSystemAppID(sSystemAppID, SystemAppID.CorpID);
            int mMemberID = SystemInfo.GetSystemAppID(sSystemAppID, SystemAppID.UserID);
            try
            {
                string connstr = SystemInfo.GetClusterConn(sSystemAppID);
                var sql = @"Exec pr_min_GetMemberData @FMemberID,@FCorpID";
                SqlParameterList parlist = new SqlParameterList();
                parlist.Add("@FMemberID", SqlDbType.BigInt, mMemberID);
                parlist.Add("@FCorpID", SqlDbType.Int, mCorpID);
                ArrayList datalist = DBHelper.Select(sql, parlist.Get_List(), connstr);
                string strData = JsonConvert.SerializeObject(datalist);
                var data = JsonConvert.DeserializeObject<List<MemberDataResponse>>(strData);
                return data;
            }
            catch (Exception e)
            {
                return null;
            }
        }        
    }
}
